package org.dxy.infrastructure.persistent.db.mybatispuls.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.dxy.infrastructure.persistent.db.mybatispuls.po.query.ProductionLineBasicViewPo;
import org.dxy.infrastructure.persistent.db.mybatispuls.mapper.ProductionLineBasicViewMapper;
import org.dxy.infrastructure.persistent.db.mybatispuls.service.ProductionLineBasicViewService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ description:
 * @ author: dxy
 * @ createTime: 2025/7/20 19:43
 */
@Slf4j
@Service
public class ProductionLineBasicViewServiceImpl extends MPJBaseServiceImpl<ProductionLineBasicViewMapper, ProductionLineBasicViewPo> implements ProductionLineBasicViewService {

    @Override
    public boolean existsByLineCode(String lineCode) {
        LambdaQueryWrapper<ProductionLineBasicViewPo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductionLineBasicViewPo::getLineCode, lineCode);
        return this.count(queryWrapper) > 0;
    }

    @Override
    public List<ProductionLineBasicViewPo> getEnabledProductionLines() {
        LambdaQueryWrapper<ProductionLineBasicViewPo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductionLineBasicViewPo::getStatus, "enable");
        queryWrapper.orderByAsc(ProductionLineBasicViewPo::getLineName);
        return this.list(queryWrapper);
    }
}
